﻿using Microsoft.Extensions.DependencyInjection;
using Tools.ViewModels;
using Tools.Views;
using System.Windows;

namespace Tools
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            Services = ConfigureServices();
        }

        /// <summary>
        /// Gets the current <see cref="App"/> instance in use
        /// </summary>
        public static new App Current => (App)Application.Current;

        /// <summary>
        /// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
        /// </summary>
        public IServiceProvider Services { get; }

        /// <summary>
        /// Configures the services for the application.
        /// </summary>
        private static IServiceProvider ConfigureServices()
        {
            var services = new ServiceCollection();
            //services.AddSingleton<MainWindow>();
            services.AddSingleton<MainViewModel>();
            services.AddSingleton<JsonViewModel>();
            services.AddTransient(sp => new JsonPage() { DataContext=sp.GetRequiredService<JsonViewModel>() });
            services.AddTransient(sp => new MainWindow() { DataContext=sp.GetRequiredService<MainViewModel>() });
            //services.AddTransient(sp => new MainPage() { DataContext=sp.GetRequiredService<KeyPressViewModelCommunityToolkit>() });

            return services.BuildServiceProvider();
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            MainWindow= Services.GetRequiredService<MainWindow>();
            MainWindow?.Show();
        }
    }

}
